/**
 *******************************************************************************
 * @FileName  : audio.h
 * @Author    : GaoQiu
 * @CreateDate: 2020-05-18
 * @Copyright : Copyright(C) GaoQiu
 *              All Rights Reserved.
 *******************************************************************************
 */


#ifndef AUDIO_H_
#define AUDIO_H_

#include "utils/defs_types.h"
#include "platform/platform.h"

typedef struct{

}AudioInput_Type_t;


typedef struct{
	__IO uint8_t CTRL;          /*!< 0x560 audio control   */
	__IO uint8_t MID_GRP;       /*!< 0x561 middle of group */
	__IO uint8_t VOL_CTRL;      /*!< 0x562 volume control  */
	__IO uint8_t PWM_CTRL;      /*!< 0x563 linear interpolate */

#if 0
	__IO uint8_t ASCL_TUNE;     /*!< 0x564 rate match */
	__IO uint8_t I2S_FCT;       /*!< 0x565 I2S factor to generate I2S clock and step */
	__IO uint8_t ASCL_STEP0;    /*!< 0x566 I2S factor to generate I2S clock and step */
	__IO uint8_t ASCL_STEP1;    /*!< 0x567 I2S factor to generate I2S clock and step */
#else
	__IO uint32_t ASCL_STEP;    /*!< 0x564 - 0x567 I2S factor to generate I2S clock and step */
#endif

	__IO uint16_t PN_LEFT;      /*!< 0x568 - 0x569 */
	__IO uint16_t PN_RIGHT;     /*!< 0x56a - 0x56b */
	__IO uint16_t CONST_LEFT;   /*!< 0x56c - 0x56d */
	__IO uint16_t CONST_RIGHT;  /*!< 0x56e - 0x56f */
}AudioOutput_Type_t;


/* AUDIO_CTRL register. *******************************************************/
#define AUDIO_CTRL_MONO_STEREO_MASK    (0x01)
#define AUDIO_CTRL_MONO                (1<<0)

#define AUDIO_CTRL_OUTPUT_MODE_MASK    (0x1E)
#define AUDIO_CTRL_OUTPUT_I2S_PLAYER   (1<<1)
#define AUDIO_CTRL_OUTPUT_SDM_PLAYER   (1<<2)
#define AUDIO_CTRL_OUTPUT_ISO_PLAYER   (1<<3)
#define AUDIO_CTRL_OUTPUT_I2S_RECORDER (1<<4)

#define AUDIO_CTRL_GRP_EN_MASK          (0x40)
#define AUDIO_CTRL_GRP_EN               (1<<6)

#define AUDIO_CTRL_HPF_EN_MASK          (0x80)
#define AUDIO_CTRL_HPF_EN               (1<<7)

/* MID_GRP register. **********************************************************/
#define AUDIO_MID_GRP_MASK              0xFF

/* VOL_CTRL register. *********************************************************/
#define AUDIO_VOL_CTRL_QUARTER          (1<<0)  /*!< add a quarter (1/4) volume */
#define AUDIO_VOL_CTRL_HALF             (1<<1)  /*!< add a half (1/2) volume */

#define AUDIO_VOL_CTRL_SHIFT_MASK       (0x1F<<2)  /*!< shift */

#define AUDIO_VOL_CTRL_MUTE             (1<<7)


/* PWM_CTRL register. *********************************************************/
#define AUDIO_PWM_CTRL_NO_MULTI           (1<<0) /*!< 1: Disable Multi; 0: Enable Multi */
#define AUDIO_PWM_CTRL_PWN                (1<<1) /*!< 1: Enable PWM; 0: Disable PWM */
#define AUDIP_PWM_CTRL_LINEAR_INTER       (1<<2) /*!< 1: linear interpolate; 0: delay interpolate. */
#define AUDIO_PWM_CTRL_LEFT_SHAPPING_EN   (1<<5) /*!< 1: left channel shapping enable */
#define AUDIO_PWM_CTRL_RIGHT_SHAPPING_EN  (1<<6) /*!< 1: right channel shapping enable */
#define AUDIO_PWM_CTRL_I2S_INPUT_SWAP     (1<<7) /*!< 1: I2S input left/right channel swap */

/* ASCL_TUNE/ASCL_STEP register. **********************************************/
#define AUDIO_ASCL_TUNE_MASK               0x000000FF
#define AUDIO_ASCL_STEP_I2S_DIV_MASK       0x00000F00
#define AUDIO_ASCL_STEP_STEP               0xFFFFF000

#endif /* AUDIO_H_ */
